package com.ldc.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ldc.model.Article;
import com.ldc.service.mapper.ArticleMapper;
import com.ldc.service.service.ArticleService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 功能描述
 *
 * @author liudi
 * @since 2023/7/23
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
    @Override
    public List<Article> findListBy(LambdaQueryWrapper<Article> queryWrapper) {
        return getBaseMapper().selectList(queryWrapper);
    }

    @Override
    public List<Article> findListByIds(List<Long> ids) {
        return findListBy(new LambdaQueryWrapper<Article>().in(Article::getId, ids));
    }

    @Override
    public int batchDeleteBy(LambdaQueryWrapper<Article> queryWrapper) {
        return getBaseMapper().delete(queryWrapper);
    }

    @Override
    public int batchDeleteByIds(List<Long> ids) {
        return batchDeleteBy(new LambdaQueryWrapper<Article>().in(Article::getId, ids));
    }

    @Override
    public List<Long> getArticleIds(List<Long> ids) {
        return findListBy(new LambdaQueryWrapper<Article>().in(Article::getId, ids)).stream().map(Article::getId).collect(Collectors.toList());
    }

    @Override
    public IPage<Article> findPageBy(int page, int limit, LambdaQueryWrapper<Article> queryWrapper) {
        return getBaseMapper().selectPage(Page.of(page, limit, true), queryWrapper);
    }
}
